	
project, uses(../data_output/termlimited.dta)
	
	
	use ../data_output/termlimited.dta, clear

	keep if pc1!=.
	gen first_year_index = regexs(1) if regexm(term, "([0-9][0-9][0-9][0-9])-")
	gen last_year_index = regexs(1) if regexm(term, "-([0-9][0-9][0-9][0-9])")
	destring first_year_index last_year_index, replace

	collapse (mean) termlimits_effective (min) first_year_index  (max) last_year_index , by(state chamber )
	sort state chamber
	by state: gen n = _n
	reshape wide  chamber, i(state) j(n)
	
	replace chamber1 =trim(chamber1+ " \& " +chamber2) if chamber2!=""
	
	cap log close
	quietly {
	
		set linesize 255
		log using "../tables_figures/termlimits_take_effect.tex", text replace
		
		noisily dis "\begin{table}[t]"
		noisily dis "\centering"
		noisily dis "\caption{\textbf{Summary of Dataset Coverage.} The table shows the states"
		noisily dis "and chambers that enter our main analysis, the years for which we have data,"
		noisily dis	"and the year in which the term limits took effect.\label{tab:summary}}"
		noisily dis "\begin{tabular}{l ccc}"
		noisily dis "\toprule \toprule"
		noisily dis "  State & Chambers & Data Range & Year When Limits  \\"
		noisily dis "   &  & & Took Effect  \\"

		noisily dis "\midrule"
		
		local n = _N
		forval i =1/`n' {
			noisily dis state[`i'] " & " chamber1[`i'] " & " first_year_index[`i'] "-" last_year_index[`i'] " & "  termlimits_effective[`i']  " \\"
			
		}
		
		
		noisily dis "\bottomrule \bottomrule"
		noisily dis "\end{tabular}"
		noisily dis "\end{table}"
		
		log off

	}
